package com.example.xml;


import java.io.IOException;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
/**
 * 抓取解析html
 * 还可以用htmlparser
 * */
@Service
public class Zhuaqu {
	private static Logger logger=LoggerFactory.getLogger(Zhuaqu.class);
	private static final String FOOTBALL_URL = "http://info.sporttery.com/football/match_list.php";
	public void getFoot(){
		try{
			Document doc=getDoc(FOOTBALL_URL);
			Element tb=doc.getElementById("jumpTable");;
			List<Element> els=tb.getElementsByTag("tr");
			for(Element el:els){
				List<Element> tds=el.getElementsByTag("td");
				if(null!=tds&&tds.size()>0){
					logger.info("抓取的全部数据{}",tds);
					logger.info("抓取的全部数据中的某个{}",tds.get(0).text().trim());
				}
				
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}
	
	public Document getDoc(String url) throws IOException{
		return Jsoup.connect(url).timeout(10000).get(); 
	}

}
